//
//  UIbutton-Extension.swift
//  CBWWeiBo
//
//  Created by 陈博文 on 16/1/8.
//  Copyright © 2016年 陈博文. All rights reserved.
//

import UIKit

extension UIButton {
    // convenience便利构造函数
    convenience init(imageName : String, bgImageName : String) {
        self.init()
        
        // 1.设置按钮的属性
        setImage(UIImage(named: imageName), forState: .Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        setBackgroundImage(UIImage(named: bgImageName), forState: .Normal)
        setBackgroundImage(UIImage(named: bgImageName + "_highlighted"), forState: .Highlighted)
        
        // 2.设置按钮的尺寸
        sizeToFit()
    }
    
    convenience init(imageName : String, target : AnyObject?, action : Selector) {
        self.init()
        
        setImage(UIImage(named: imageName), forState: .Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        sizeToFit()
        addTarget(target, action: action, forControlEvents: .TouchUpInside)
    }

}
